package com.bird.thread.base.sixstaus;

/**
 * @author: bird
 * @Data: 2021/6/29 17:07
 * @description: 展示 new runnable terminated线程流转的三个状态
 * 即使是正在运行,也是Runnable状态 而不是Running的状态。
 */
public class NewRunnableTerminated implements Runnable {


    public static void main(String[] args) {

        Thread thread = new Thread(new NewRunnableTerminated());

        // 打印thread-NEW的状态
        System.out.println(thread.getState());

        // 启动这个线程
        thread.start();
        // 打印thread-RUNNABLE的状态
        System.out.println(thread.getState());

        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 打印出RUNNABLE的状态,即使是正在运行,也是RUNNABLE 而不是RUNNING
        System.out.println(thread.getState());


        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 打印出 TERMINATED状态
        System.out.println(thread.getState());
    }


    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
        }
    }
}
